local zhiliu = fk.CreateSkill{
  name = "wk_heg__zhiliu",
}


Fk:loadTranslationTable{
  ["wk_heg__zhiliu"] = "治流",
  [":wk_heg__zhiliu"] = "出牌阶段开始时，你可将一张牌交给一名其他角色，然后若以此法获得牌的角色本回合未以此法失去过牌，其可以重复牌数+1的此流程。",
  
  ["#wk_heg__zhiliu-give"] = "治流：你可以交给一名其他角色 你以此法获得牌数+1 张牌，然后其可重复此流程",

  ["$wk_heg__zhiliu1"] = "兴凿修渠，依水屯军！",
  ["$wk_heg__zhiliu2"] = "开渠疏道，以备军实！",
}

--- 治流递归
---@param room Room
---@param player ServerPlayer
---@param num integer
local function AskForContinueZhiliu(room, player, num)
  local targets = table.filter(room.alive_players, function (p) return p ~= player end)
  local tos, id = room:askToChooseCardsAndPlayers(player, {
    targets = targets, 
    min_num = 1, 
    max_num = 1,
    min_card_num = num, 
    max_card_num = num, 
    pattern = ".|.|.|.|.|.",
    propmt = "#wk_heg__zhiliu-give",
    skill_name = zhiliu.name,
    cancelable = true,
  })
  if #tos > 0 then
    room:obtainCard(tos[1], id, false, fk.ReasonGive)
    room:setPlayerMark(player, "wk_heg__zhiliu-turn", 1)
    if tos[1]:getMark("wk_heg__zhiliu-turn") == 0 then
      AskForContinueZhiliu(room, tos[1], num + 1)
    end
  end
end

zhiliu:addEffect(fk.EventPhaseStart, {
  anim_type = "special",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) and player == target and player.phase == Player.Play and not player:isNude()
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    AskForContinueZhiliu(room, player, 1)
  end,
})

return zhiliu